<?php
 ini_set('display_errors', '0');
include("connect.php");

	$firstColTotal = 0;
	$secondColTotal = 0;
	$bothColsTotal = 0;

?>
<!DOCTYPE html>
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta charset="utf-8">
	 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <title>AP Forest Department R &amp; D Circle</title> 
	<link rel="shortcut icon" type="image/x-icon" href="images/favicon.png" /> 	
	<link href='http://fonts.googleapis.com/css?family=Monda' rel='stylesheet' type='text/css'>
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
	<link href="css/style.css" rel="stylesheet">
	<link href="css/aptable-responsive.css" rel="stylesheet">	
    <link href="css/custom.css" rel="stylesheet" type="text/css">
</head>
<body>
    <div class="container" style="position:relative;"> 
<div class="" style="position:absolute;top:10px;right:10px;text-transform:uppercase">
	<?php session_start(); 
		if(isset($_SESSION['issess']) && $_SESSION['issess']!='')
		{?>
		<a style="float:left" href="changepassword.php">Change Password</a>&nbsp;&nbsp;&nbsp;&nbsp;
		<a style="float:right" href="logout.php">Logout</a>	
	<?}else{header("location:ap-admin.php");}?>	
</div>	
    <div class="well row">    
				<div class="logo view_mar_top">
						<img src="images/apfd-Logo.png"/>					
				</div>
				
				<div class="apdiv">
					<h1>ANDHRA PRADESH FOREST DEPARTMENT</h1>
				</div>
				<div class="apdiv">
					<h2>RESEARCH AND DEVELOPMENT CIRCLE</h2>
				</div>
				<div class="apdiv">
					<h3>SEED AVAILABILITY INFORMATION</h3>
				</div>
				<div class="apdiv">
					<div class="span10">
						<p>This information reflects the quantities of seed of various species available with the two Research Divisions of Andhra Pradesh Forest Department and is updated continuously. Required quantities may be indented from the Reseach Divisions with whom the seeds are available. While indenting with the Research Division, please mark a copy of the indent to the APCCF(R&D) for information.</p>
						<p>If you need the seed of any of the species other than those listed below, please place an indent well in time along with the information such as the nursery season for which the seeds are required.</p>
					</div>
				</div>
				<!--<div class="ap_item_per_kg">
					<p>( Quantities are in KGs ) </p>
				</div>-->
				
                <div class="sap">
                <div class="table_bg">
					<div class="span10">
						<div class="ap_editable_table">
						<button class="addnew_row" id="add" onclick="addnewrow()">Add New</button>
						<div class="clear"></div>
                    <table class= "table table-striped table-bordered table-hover ap_table" >
                       <thead>
                            <tr>

                                <th>Botanical name</th>

                                <th>Common Name</th>

                                <th>SS, Rajahmundry</th>
								<th>SS, Tirupathi</th>
								<th>TOTAL</th>
								<th>Remarks</th>
								<th>Action</th>
                            </tr>
                        </thead>

                        <tbody>
                        <?php
						ini_set('display_errors', '0');
						$query = mysql_query("SELECT * FROM information ORDER BY bname ASC");

						$i=0;
						while($fetch = mysql_fetch_array($query))
						{
							if($i%2==0) $class = 'even'; else $class = 'odd';
							
							echo'<tr class="'.$class.'" id="tr_'.$fetch['id'].'">

                                <td><span class= "xedit" id="'.$fetch['id'].'" name="bname">'.$fetch['bname'].'</span></td>
                                <td><span class= "xedit" id="'.$fetch['id'].'"  name="cname">'.$fetch['cname'].'</span></td>
                                <td><span class= "xedit" id="'.$fetch['id'].'"  name="ssr">'.$fetch['ssr'].'</span></td>
								<td><span class= "xedit" id="'.$fetch['id'].'"  name="sst">'.$fetch['sst'].'</span></td>
								  <td><span id="totalCol_'.$fetch['id'].'"  name="total">'.($fetch['ssr']+$fetch['sst']).'</span></td>
								   <td><span class= "xedit" id="'.$fetch['id'].'"  name="remarks">'.$fetch['remarks'].'</span></td>
								    <td><img src="images/delete.png" id="'.$fetch['id'].'" onClick="deleteFun('.$fetch['id'].')" alt="Delete" title="Delete"/></td>
                            </tr>';	
						echo '<input type="hidden" id="hidid" name="hidid" value="'.$fetch['id'].'" />';
						
						echo '<input type="hidden" id="delssr'.$fetch['id'].'" name="delssr'.$fetch['id'].'" value="'.$fetch['ssr'].'" />';
						echo '<input type="hidden" id="delsst'.$fetch['id'].'" name="delsst'.$fetch['id'].'" value="'.$fetch['sst'].'" />';

						$firstColTotal += $fetch['ssr'];
						$secondColTotal += $fetch['sst'];
						$bothColsTotal = $firstColTotal + $secondColTotal; 
						
						}
						?>

						<tr>
                                <th>&nbsp;</th>
                                <th>&nbsp;</th>
                                <th id="firstColTotal"><?php echo $firstColTotal;?></th>
								<th id="secondColTotal"><?php echo $secondColTotal;?></th>
								<th id="bothColsTotal"><?php echo $bothColsTotal;?></th>
								<th>&nbsp;</th>
								<th>&nbsp;</th>
                        </tr>

                        </tbody>
						
                    </table>
					
					<input type="hidden" id="preval" value="0" />
					<input type="hidden" id="postval" value="0" />

					<input type="hidden" id="firstColVar" value="<?php echo $firstColTotal;?>" />
					<input type="hidden" id="secondColVar" value="<?php echo $secondColTotal;?>" />
					<input type="hidden" id="bothColsVar" value="<?php echo $bothColsTotal;?>" />

					<input type="hidden" id="newRowStatus" value="0" />

					</div>
				</div>
        </div>
		
	</div>
	<div class="clear"></div>
	<div class="apdiv_bottom">
					<h3>CELL NUMBERS OF RESEARCH OFFICERS </h3>
				</div>
				<div class="apdiv_bottom_p">
				<p>These numbers are for enquiries only. Indents need to be placed in writing. Kindly follow up all oral indents with written indents.</p>
					<p>Developed and maintained by the Research & Development Circle, Andhra Padesh Forest Department.</p>
					<p>Please send suggestions on further improvement of this webpage to <a href="mailto:bvpreddy@gmail.com">bvpreddy@gmail.com</a></p>

				</div>
	</div>
		<script src="js/jquery.min.js"></script> 
		<script src="js/bootstrap.min.js"></script>
        <script src="js/bootstrap-editable.js" type="text/javascript"></script> 
<script type="text/javascript">

function setPreval( ele,val ){
	// alert( isNaN(val) );

	if( $("#txtssr").val() != "" )
	{
		var ssrArr = $("#txtssr").val().split(".");
		// alert( ssrArr.length );
		if( ssrArr.length > 1 )
		{
			if( ssrArr.length > 2 )
			{
				alert( "Please enter proper decimal number." );
				window.setTimeout(function(){ele.focus();}, 100);
				return false;
			}
			for( posCount = 0; posCount < ssrArr.length; posCount++ )
			{
				if( ssrArr[posCount] == "" )
				{
					alert( "Please enter proper decimal number." );
					window.setTimeout(function(){ele.focus();}, 100);
					return false;
				}
			}
		}
	}

	if( val == "" )
	{
		val = 0;
	}
	$("#preval").val(val);
	var total = parseFloat($("#postval").val())+parseFloat(val);
	if( parseFloat(total) == 0 )
	{
		$("#txttotal").html( "" );
	}
	else
	{
		if( total % 1 === 0 )
		{
			$("#txttotal").html( total );
		}
		else
		{
			$("#txttotal").html( total.toFixed(2) );
		}
	}
}

function setTotal( ele,val ){

	if( $("#txtsst").val() != "" )
	{
		var sstArr = $("#txtsst").val().split(".");
		// alert( sstArr.length );
		if( sstArr.length > 1 )
		{
			if( sstArr.length > 2 )
			{
				alert( "Please enter proper decimal number." );
				window.setTimeout(function(){ele.focus();}, 100);
				return false;
			}
			for( posCount = 0; posCount < sstArr.length; posCount++ )
			{
				if( sstArr[posCount] == "" )
				{
					alert( "Please enter proper decimal number." );
					window.setTimeout(function(){ele.focus();}, 100);
					return false;
				}
			}
		}
	}

	if( val == "" )
	{
		val = 0;
	}
	$("#postval").val(val);
	var total1 = parseFloat($("#preval").val())+parseFloat(val);
	if( parseFloat(total1) == 0 )
	{
		$("#txttotal").html( "" );
	}
	else
	{
		if( total1 % 1 === 0 )
		{
			$("#txttotal").html( total1 );
		}
		else
		{
			$("#txttotal").html( total1.toFixed(2) );
		}
	}
} 

function addnewrow()
{
	if( $("#newRowStatus").val() != "" )
	{
		if( parseInt($("#newRowStatus").val()) == 1 )
		{
			alert( "Please save or cancel new row added." );
			return false;
		}
	}
	
	var curid=parseInt($("#hidid").val())+1;
	$(".table").prepend("<tr id='added'><td><input type='text' id='txtbname'  class='ap_Admin_control_input'/></td><td><input type='text' id='txtcname' class='ap_Admin_control_input'/></td><td><input type='text' id='txtssr' name='txtssr' class='ap_Admin_control_input' onblur='setPreval(this,this.value)'/></td><td><input type='text' class='ap_Admin_control_input' id='txtsst' name='txtsst' onblur='setTotal(this,this.value)' /></td><td id='txttotal'>&nbsp;</td><td><input type='text' class='ap_Admin_control_input' id='txtremarks'/>&nbsp;</td><td><img src='images/save.png' id='save' name='save' alt='save icon' title='Save' onClick='addNew()'/>&nbsp;&nbsp;&nbsp;<img src='images/close.png' name='cancel'  onClick='cancelNew()' alt='Close icon' title='Close'/></td></tr>");
	$.fn.editable.defaults.mode = 'popup';
	$('.xedit').editable();
	
			$('input[name="txtssr"]').keydown(function (e) {
	                var keyCode = e.which; // Capture the event
	 
	                //190 is the key code of decimal if you dont want decimals remove this condition keyCode != 190
	                if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 37 && keyCode != 38 && keyCode != 39 && keyCode != 40 && keyCode != 46 && keyCode != 110 && keyCode != 190) {
	                    if (keyCode < 48) {
	                        e.preventDefault();
	                    }
	                    else if (keyCode > 57 && keyCode < 96) {
	                        e.preventDefault();
	                    }
	                    else if (keyCode > 105) {
	                        e.preventDefault();
	                    }
	                }
	            });	
	
			$('input[name="txtsst"]').keydown(function (e) {
	                var keyCode = e.which; // Capture the event
	 
	                //190 is the key code of decimal if you dont want decimals remove this condition keyCode != 190
	                if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 37 && keyCode != 38 && keyCode != 39 && keyCode != 40 && keyCode != 46 && keyCode != 110 && keyCode != 190) {
	                    if (keyCode < 48) {
	                        e.preventDefault();
	                    }
	                    else if (keyCode > 57 && keyCode < 96) {
	                        e.preventDefault();
	                    }
	                    else if (keyCode > 105) {
	                        e.preventDefault();
	                    }
	                }
	            });	

			$("#newRowStatus").val( 1 );
		
	}

function addNew()
{	
	
	var bname = $("#txtbname").val();
	   
	if(bname==""){
			alert('Please enter botanical name.');return false;
		}

	var cname = $("#txtcname").val();
	
	var rajahmundry1 = "";
	var tirupathi1 = "";
	var total1 = "";
	var rajahmundry = 0;
	var tirupathi = 0;
	
	// alert( $("#txtssr").val() );
	// alert( $("#txtsst").val() );
	
	if( $("#txtssr").val() != "" )
	{
		rajahmundry = parseFloat($("#txtssr").val());
		rajahmundry1 = parseFloat($("#txtssr").val());
	}
	if( $("#txtsst").val() != "" )
	{
		tirupathi = parseFloat($("#txtsst").val());
		tirupathi1 = parseFloat($("#txtsst").val());
	}
	// return false;
	
	// var rajahmundry = parseFloat($("#txtssr").val());
	//var tirupathi = parseFloat($("#txtsst").val());
	
	var total = parseFloat(rajahmundry)+parseFloat(tirupathi);

	if( parseFloat(total) != 0 )
	{
		total1 = parseFloat(total);
		
		if( total % 1 === 0 )
		{
			// $("#txttotal").html( total );
		}
		else
		{
			total = total.toFixed(2);
			// alert( total );
			total1 = total1.toFixed(2);
		}
	}

	var remarks = $("#txtremarks").val();
	
	$.ajax({
			url: "insert.php",
			type: 'POST',
			data: {bname:bname,cname:cname,rajahmundry:rajahmundry,tirupathi:tirupathi,remarks:remarks},
			success: function(id){
			id= id.trim(); 
			
			$("#added").remove();
			var ssrsstEdited = 0;

			var newRowHtml = "<tr id='tr_"+id+"' class='even'><td><span class= 'xedit editable editable-click' id='"+id+"' name='bname'>"+bname+"</span></td><td><span class= 'xedit editable editable-click' id='"+id+"' name='cname'>"+cname+"</span></td><td><span class= 'xedit editable editable-click' id='"+id+"' name='ssr'>"+rajahmundry1+"</span></td><td><span class= 'xedit editable editable-click' id='"+id+"' name='sst'>"+tirupathi1+"</span></td><td id='totalCol_"+id+"'>&nbsp;"+total1+"</td><td><span class= 'xedit editable editable-click' id='"+id+"' name='remarks'>"+remarks+"</span></td><td><img src='images/delete.png' id='"+id+"' onClick='deleteData("+id+","+rajahmundry+","+tirupathi+")' /><input type='hidden' id='delssr"+id+"' name='delssr' value="+rajahmundry+" /><input type='hidden' id='delsst"+id+"' name='delsst' value="+tirupathi+" /></td></tr>";
			if(id>=0){
				window.location='admin-page.php';
			}
			//$(".table").prepend( newRowHtml );
			
	$.fn.editable.defaults.mode = 'popup';
        $('.xedit').editable();
		
		// alert( $("#tr_"+id).length );

		if( ($("#firstColVar").val() != "") && ($("#preval").val() != "") )
		{
			$("#firstColVar").val( parseFloat($("#firstColVar").val()) + parseFloat($("#preval").val()) );
			// $("#firstColTotal").html( $("#firstColVar").val() );
			var firstColTotal = parseFloat($("#firstColVar").val());
			if( parseFloat(firstColTotal) == 0 )
			{
				$("#firstColTotal").html( "" );
			}
			else
			{
				if( firstColTotal % 1 === 0 )
				{
					$("#firstColTotal").html( firstColTotal );
				}
				else
				{
					$("#firstColTotal").html( firstColTotal.toFixed(2) );
				}
			}
		}
		if( ($("#secondColVar").val() != "") && ($("#postval").val() != "") )
		{
			$("#secondColVar").val( parseFloat($("#secondColVar").val()) + parseFloat($("#postval").val()) );
			// $("#secondColTotal").html( $("#secondColVar").val() );
			var secondColTotal = parseFloat($("#secondColVar").val());
			if( parseFloat(secondColTotal) == 0 )
			{
				$("#secondColTotal").html( "" );
			}
			else
			{
				if( secondColTotal % 1 === 0 )
				{
					$("#secondColTotal").html( secondColTotal );
				}
				else
				{
					$("#secondColTotal").html( secondColTotal.toFixed(2) );
				}
			}
		}
		
		var bothColsTotal = parseFloat($("#firstColVar").val()) + parseFloat($("#secondColVar").val());
		// alert( $("#firstColVar").val() );
		// alert( $("#secondColVar").val() );
		// alert( bothColsTotal );

		// Imp change to basic grand total logic.
		if( bothColsTotal % 1 === 0 )
		{
			$("#bothColsTotal").html( bothColsTotal );
		}
		else
		{
			$("#bothColsTotal").html( bothColsTotal.toFixed(2) );
		}
		
		$("#preval").val( 0 );
		$("#postval").val( 0 );

		$("#newRowStatus").val( 0 );
		

		}
		
	});	
	
}

function cancelNew()
{
	
	$("#added").remove();

	$("#preval").val( 0 );
	$("#postval").val( 0 );
	
	$("#newRowStatus").val( 0 );
}

function deleteData( id,delssr1,delsst1 )
{
	if(confirm("Are you sure you want delete record?")){
				

		$.ajax({
				url: "delete.php",
				type: 'POST',
				data: {id:id},
				success: function(s){
				
				// Overriding parameters.
				
				// alert( $("#delssr"+id).length );
				// alert( $("#delsst"+id).length );
				
				var delssr = $("#delssr" + id).val();
				var delsst = $("#delsst" + id).val();
				// alert( delssr );
				// alert( delsst );

				if( ($("#firstColVar").val() != "") && (delssr != "") )
				{
					$("#firstColVar").val( parseFloat($("#firstColVar").val()) - parseFloat(delssr) );
					var firstColTotal = parseFloat($("#firstColVar").val());
					if( parseFloat(firstColTotal) == 0 )
					{
						$("#firstColTotal").html( "" );
					}
					else
					{
						if( firstColTotal % 1 === 0 )
						{
							$("#firstColTotal").html( firstColTotal );
						}
						else
						{
							$("#firstColTotal").html( firstColTotal.toFixed(2) );
						}
					}
				}
				if( ($("#secondColVar").val() != "") && (delsst != "") )
				{
					$("#secondColVar").val( parseFloat($("#secondColVar").val()) - parseFloat(delsst) );
					// $("#secondColTotal").html( $("#secondColVar").val() );
					var secondColTotal = parseFloat($("#secondColVar").val());
					if( parseFloat(secondColTotal) == 0 )
					{
						$("#secondColTotal").html( "" );
					}
					else
					{
						if( secondColTotal % 1 === 0 )
						{
							$("#secondColTotal").html( secondColTotal );
						}
						else
						{
							$("#secondColTotal").html( secondColTotal.toFixed(2) );
						}
					}
				}
				var bothColsTotal = parseFloat($("#firstColVar").val()) + parseFloat($("#secondColVar").val());

				if( bothColsTotal % 1 === 0 )
				{
					$("#bothColsTotal").html( bothColsTotal );
				}
				else
				{
					$("#bothColsTotal").html( bothColsTotal.toFixed(2) );
				}

				$("#tr_"+id).remove();

				if(s == 'status'){
					$(z).html(y);}
					if(s == 'error') {
					alert('Error Processing your Request!');}
				},
				error: function(e){
					alert('Error Processing your Request!!');
				}
		});

			// $("#added").remove();
			// alert( $("#tr_"+id).length );
			
			
			// alert( $("#tr_"+id).length );
			
		
	}	
}

function deleteFun(id)
{
	if(confirm("Are you sure you want delete record?")){
		$.ajax({
				url: "delete.php",
				type: 'POST',
				data: {id:id},
				success: function(s){
				
					var delssr = $("#delssr" + id).val();
					var delsst = $("#delsst" + id).val();
					// alert( delssr );
					// alert( delsst );
					if( ($("#firstColVar").val() != "") && ($("#delssr" + id).val() != "") )
					{
						$("#firstColVar").val( parseFloat($("#firstColVar").val()) - parseFloat($("#delssr" + id).val()) );
						// $("#firstColTotal").html( $("#firstColVar").val() );
						var firstColTotal = parseFloat($("#firstColVar").val());
						if( parseFloat(firstColTotal) == 0 )
						{
							$("#firstColTotal").html( "" );
						}
						else
						{
							if( firstColTotal % 1 === 0 )
							{
								$("#firstColTotal").html( firstColTotal );
							}
							else
							{
								$("#firstColTotal").html( firstColTotal.toFixed(2) );
							}
						}
					}
					if( ($("#secondColVar").val() != "") && ($("#delsst" + id).val() != "") )
					{
						$("#secondColVar").val( parseFloat($("#secondColVar").val()) - parseFloat($("#delsst" + id).val()) );
						// $("#secondColTotal").html( $("#secondColVar").val() );
						var secondColTotal = parseFloat($("#secondColVar").val());
						if( parseFloat(secondColTotal) == 0 )
						{
							$("#secondColTotal").html( "" );
						}
						else
						{
							if( secondColTotal % 1 === 0 )
							{
								$("#secondColTotal").html( secondColTotal );
							}
							else
							{
								$("#secondColTotal").html( secondColTotal.toFixed(2) );
							}
						}
					}
					var bothColsTotal = parseFloat($("#firstColVar").val()) + parseFloat($("#secondColVar").val());

					if( bothColsTotal % 1 === 0 )
					{
						$("#bothColsTotal").html( bothColsTotal );
					}
					else
					{
						$("#bothColsTotal").html( bothColsTotal.toFixed(2) );
					}
					
						if(s == 'status'){
						$(z).html(y);}
						if(s == 'error') {
						alert('Error Processing your Request!');}
				},
				error: function(e){
					alert('Error Processing your Request!!');
				}
		});	
			$("#tr_"+id).remove();
	}	
}
jQuery(document).ready(function() {  
        $.fn.editable.defaults.mode = 'popup';
        $('.xedit').editable();		
		$(document).on('click','.editable-submit',function(){
			var x = $(this).closest('td').children('span').attr('id');
			var name = $(this).closest('td').children('span').attr('name');
			var flag=true;
			var y = $('.input-sm').val();
			
			if( name == "bname" )
			{
				if( y == "" )
				{
					alert( "Please enter botanic name." );
					return false;
				}
				if( ! isNaN(y) )
				{
					alert( "Please enter text only, not numbers." );
					return false;
				}
			}
			else if( (name == "ssr") || (name == "sst") )
			{
				// alert( name );
				if( isNaN(y) )
				{
					alert( "Please enter a number." );
					return false;
				}
			}
			else if( (name == "cname") || (name == "remarks") )
			{
				// alert( name );
				if( y != "" )
				{
					if( ! isNaN(y) )
					{
						alert( "Please enter text only, not numbers." );
						return false;
					}
				}
			}
			
			// alert( "#" + y + "#" );
			// alert( "#" + isNaN(y) + "#" );
			
			// alert( $("#delssr" + x).val() );
			var val = $("#delssr" + x).val();
			var val1 = $("#delsst" + x).val();
			
			if( val == "" )
			{
				val = 0;
			}
			if( val1 == "" )
			{
				val1 = 0;
			}
			var newVal = 0;
			if( y != "" )
			{
				newVal = y;
			}
			// alert( "#" + newVal + "#");
			if( name == "ssr" )
			{
				$("#delssr" + x).val(newVal);
				var total = parseFloat(val1)+parseFloat(newVal);
				if( parseFloat(total) == 0 )
				{
					$("#totalCol_" + x).html( "&nbsp;" );
				}
				else
				{
					// alert( total );
					if( total % 1 === 0 )
					{
						$("#totalCol_" + x).html( total );
					}
					else
					{
						$("#totalCol_" + x).html( total.toFixed(2) );
					}
				}
				
				if( $("#firstColVar").val() != "" )
				{
					$("#firstColVar").val( parseFloat($("#firstColVar").val()) - parseFloat(val) );
					$("#firstColVar").val( parseFloat($("#firstColVar").val()) + parseFloat(newVal) );
					// $("#firstColTotal").html( $("#firstColVar").val() );
					var firstColTotal = parseFloat($("#firstColVar").val());
					if( parseFloat(firstColTotal) == 0 )
					{
						$("#firstColTotal").html( "" );
					}
					else
					{
						if( firstColTotal % 1 === 0 )
						{
							$("#firstColTotal").html( firstColTotal );
						}
						else
						{
							$("#firstColTotal").html( firstColTotal.toFixed(2) );
						}
					}

					var bothColsTotal = parseFloat($("#firstColVar").val()) + parseFloat($("#secondColVar").val());
					if( bothColsTotal % 1 === 0 )
					{
						$("#bothColsTotal").html( bothColsTotal );
					}
					else
					{
						$("#bothColsTotal").html( bothColsTotal.toFixed(2) );
					}
				}
			}
			else if( name == "sst" )
			{
				$("#delsst" + x).val(newVal);
				var total1 = parseFloat(val)+parseFloat(newVal);
				if( parseFloat(total1) == 0 )
				{
					$("#totalCol_" + x).html( "&nbsp;" );
				}
				else
				{
					if( total1 % 1 === 0 )
					{
						$("#totalCol_" + x).html( total1 );
					}
					else
					{
						$("#totalCol_" + x).html( total1.toFixed(2) );
					}
				}

				if( $("#secondColVar").val() != "" )
				{
					$("#secondColVar").val( parseFloat($("#secondColVar").val()) - parseFloat(val1) );
					$("#secondColVar").val( parseFloat($("#secondColVar").val()) + parseFloat(newVal) );
					// $("#secondColTotal").html( $("#secondColVar").val() );
					var secondColTotal = parseFloat($("#secondColVar").val());
					if( parseFloat(secondColTotal) == 0 )
					{
						$("#secondColTotal").html( "" );
					}
					else
					{
						if( secondColTotal % 1 === 0 )
						{
							$("#secondColTotal").html( secondColTotal );
						}
						else
						{
							$("#secondColTotal").html( secondColTotal.toFixed(2) );
						}
					}

					var bothColsTotal = parseFloat($("#firstColVar").val()) + parseFloat($("#secondColVar").val());
					if( bothColsTotal % 1 === 0 )
					{
						$("#bothColsTotal").html( bothColsTotal );
					}
					else
					{
						$("#bothColsTotal").html( bothColsTotal.toFixed(2) );
					}
				}
			}
			
			var z = $(this).closest('td').children('span');
			$(z).css({"font-weight":"normal"});
		
			$.ajax({
				url: "process.php",
				type: 'POST',
				data: {column:name,id:x,content:y},
				success: function(s){
					if(s == 'status'){
					$(z).html(y);
					
					}
					if(s == 'error') {
					alert('Error Processing your Request!');}
				},
				error: function(e){
					alert('Error Processing your Request!!');
				}
			});
		});
});
</script>
    </div>
	
</body>
</html>